package com.sample.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sample.action.form.FamilyMessageForm;
import com.sample.javabean.FamilyMessage;
import com.sample.javabean.Familyrecordmessage;
import com.sample.util.Pager;


/**
 * @version 1.0
 * @author Administrator
 *
 */
public class FamilyMessageAction extends BaseAction{
	

	private static final long serialVersionUID = -320336055651501234L;
	private final static Log log=LogFactory.getLog(FamilyMessageAction.class);
	private Pager<FamilyMessage> pageList;
	private String family_id;
	private FamilyMessage fmessage=new FamilyMessage();
	private FamilyMessageForm familyform=new FamilyMessageForm();
	private List<Familyrecordmessage> familyrecordmessageList;
	private int id;
	
	/**
	 * 添加
	 */
	public String inputFamily()throws Exception{
		Familyrecordmessage familyrecordmessage=new Familyrecordmessage();
		familyrecordmessageList =familyrecordmessage.findAll();

		return "inputFamily";
	}
	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save()throws Exception{
		try{
			if(familyform!=null){
			   FamilyMessage fmessage =new FamilyMessage();
			   fmessage.setFamily_id(familyform.getFamily_id());
			   fmessage.setCardNo(familyform.getCardNo());
			   fmessage.setFamily_name(familyform.getFamily_name());
			   fmessage.setPersNumber(familyform.getPersNumber());
			   fmessage.setAddress(familyform.getAddress());
			   fmessage.setTel(familyform.getTel());
			   fmessage.setInvNumber(familyform.getInvNumber());
			   fmessage.setSex(familyform.getSex());
			   fmessage.setRelationship(familyform.getRelationship());
			   fmessage.setJoinYear(familyform.getJoinYear());
			   fmessage.add();
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			
		}
		return "inputFamily";
	}
	/**
	 * 删除
	 */
	public String delFamily()throws Exception{
		try{
			if(familyform!=null){
				fmessage.setId(id);
				fmessage.delFamilyMessage();	
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}	
	}
	/**
	 * 修改
	 */
	public String editFamily()throws Exception{
		try{
			fmessage.setId(id);
			fmessage.load();
			return "editFamily";
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}	
	}
	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String edit()throws Exception{
		try{
			if(familyform!=null){
				   fmessage.setId(familyform.getId());
				   fmessage.setFamily_id(familyform.getFamily_id());
				   fmessage.setCardNo(familyform.getCardNo());
				   fmessage.setFamily_name(familyform.getFamily_name());
				   fmessage.setPersNumber(familyform.getPersNumber());
				   fmessage.setAddress(familyform.getAddress());
				   fmessage.setTel(familyform.getTel());
				   fmessage.setInvNumber(familyform.getInvNumber());
				   fmessage.setSex(familyform.getSex());
				   fmessage.setRelationship(familyform.getRelationship());
				   fmessage.setJoinYear(familyform.getJoinYear());
				   fmessage.editFamilyMessage();	
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}	
	}
	
	public String list()throws Exception{
		
		FamilyMessage  familymessage =new FamilyMessage();
		pageList =familymessage.list(page, size, familyform);
		log.info("加载家庭成员信息");
		return "listFamily";
	}
	
	
	public Pager<FamilyMessage> getPageList() {
		return pageList;
	}
	public void setPageList(Pager<FamilyMessage> pageList) {
		this.pageList = pageList;
	}
	public String getFamily_id() {
		return family_id;
	}
	public void setFamily_id(String family_id) {
		this.family_id = family_id;
	}
	public FamilyMessage getFmessage() {
		return fmessage;
	}
	public void setFmessage(FamilyMessage fmessage) {
		this.fmessage = fmessage;
	}
	public FamilyMessageForm getFamilyform() {
		return familyform;
	}
	public void setFamilyform(FamilyMessageForm familyform) {
		this.familyform = familyform;
	}
	
	public List<Familyrecordmessage> getFamilyrecordmessageList() {
		return familyrecordmessageList;
	}
	public void setFamilyrecordmessageList(
			List<Familyrecordmessage> familyrecordmessageList) {
		this.familyrecordmessageList = familyrecordmessageList;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public static Log getLog() {
		return log;
	}

}